package com.platform.common.util;

import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import java.util.Map;

public class ListSortUtil {

	public static void desc(List<Map<String, Object>> list) {

		Collections.sort(list, new Comparator<Map<String, Object>>() {

			@Override
			public int compare(Map<String, Object> o1, Map<String, Object> o2) {

				String s1 = (String) o1.get("Time");
				String s2 = (String) o2.get("Time");

				
				if (s1 != null && s2 != null)
					return s1.compareTo(s2);
				else if (s1 == null && s2 == null)
					return 0;
				else if (s1 == null)
					return -1;
				else
					return 1;
			}
		});
	}

	public static void asc(List<Map<String, Object>> list) {

		desc(list);
		Collections.reverse(list);
	}

	public static void listSortString(List<String> list) {

		Collections.sort(list, new Comparator<String>() {

			@Override
			public int compare(String s1, String s2) {
				if (s1 != null && s2 != null)
					return s1.compareTo(s2);
				else if (s1 == null && s2 == null)
					return 0;
				else if (s1 == null)
					return -1;
				else
					return 1;
			}
		});
	}
}
